#!/usr/bin/env python


from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.api import taskqueue

import logging
import sys

from Schedule import CallScheduleGenerator

class MainHandler(webapp.RequestHandler):
    def get(self):
        self.response.out.write(sys.version)
        self.response.out.write('Hello world!')
        
class ScheduleHandler(webapp.RequestHandler):
    def get(self):
        taskqueue.add(url='/worker', params={'key': 1})
        self.redirect('/')

class WorkerHandler(webapp.RequestHandler):
    def get(self):
        self.response.out.write('WorkerHandler')
        logging.info('WorkerHandler')
        
        a = CallScheduleGenerator.CallScheduleGenerator(logging)
        a.run()
                
    def post(self):
        logging.info('WorkerHandler')
        self.get()

def main():
    application = webapp.WSGIApplication([
                                          ('/', MainHandler),
                                          ('/schedule', ScheduleHandler),
                                          ('/worker', WorkerHandler),
                                          ],
                                         debug=True)
    util.run_wsgi_app(application)


if __name__ == '__main__':
    main()
